﻿#include "CPointMgrBase.h"
#include "CHeader.h"

CPointMgrBase::CPointMgrBase(CBeltDataBase * pBeltData)
{
	m_pBeltData = pBeltData;
	m_pTimer = new QTimer(this);
	createPoints();
	m_pTimer->setTimerType(Qt::TimerType::PreciseTimer);
	connect(m_pTimer, &QTimer::timeout, this, &CPointMgrBase::refreshData);
}


void CPointMgrBase::createPoints()
{
	CMeasurePoint *pDevState = new CMeasurePoint("DevState", A2T("设备状态"), "", NULL, EPointType::enDigital);
	CMeasurePoint *pAlarmType = new CMeasurePoint("AlarmType", A2T("撕裂状态"), "", NULL, EPointType::enDigital);
	CMeasurePoint *pKaMax = new CMeasurePoint("KaMax", A2T("最大曲率"), "", NULL, EPointType::enAnalog);
	CMeasurePoint *pLineHight = new CMeasurePoint("LineHight", A2T("激光线高度"), "", NULL, EPointType::enAnalog);
	CMeasurePoint *pWipersWork = new CMeasurePoint("LineHight", A2T("雨刮器运行"), "", NULL, EPointType::enDigital);
	m_vecPoints.push_back(pDevState);
	m_vecPoints.push_back(pAlarmType);
	m_vecPoints.push_back(pKaMax);
	m_vecPoints.push_back(pLineHight);
	m_vecPoints.push_back(pWipersWork);
}

CPointMgrBase::~CPointMgrBase()
{

}
QList<CMeasurePoint*> CPointMgrBase::getPoint()
{
	return m_vecPoints;
}

void CPointMgrBase::start()
{
	if (!m_pTimer->isActive())
	{
		m_pTimer->start(1000);
	}
}

void CPointMgrBase::stop()
{
	if (m_pTimer->isActive())
	{
		m_pTimer->stop();
	}
}

void CPointMgrBase::refreshData()
{
	/**
	* @ Author: Gaojia
	* @ Description: 刷新测点数据
	*/
	if (m_pBeltData->m_pMutex->tryLock(50))
	{
		m_vecPoints[0]->setValue(m_pBeltData->m_bBeltWork);
		m_vecPoints[1]->setValue(m_pBeltData->m_nAlarmType);
		m_vecPoints[2]->setValue(m_pBeltData->m_nMaskSum);
		m_vecPoints[3]->setValue(m_pBeltData->m_nLineHight);
		m_vecPoints[4]->setValue(m_pBeltData->m_bWipersWork);
		if(m_pBeltData->m_mapInputPoint.contains("0"))
		m_pBeltData->m_bBeltWork = m_pBeltData->m_mapInputPoint["0"]->getValue().toBool();
		m_pBeltData->m_pMutex->unlock();
	}

}